//: Swift3 xl day 1
import UIKit

// MARK: - ??
let name:String? = "bar"

//?? 优先级低,在使用时,最好加上()
print(name ?? "" + "foo")
print((name ?? "") + "foo")

//MARK: -  if let/var
let oName: String? = "baz"
let oAge: Int? = 10

if let name = oName, let age = oAge{
    print(name + String(age))
}

if var name = oName, let age = oName {
    name = "qwe"
    print(name + String(age))
}

//MARK: - guard 与if else刚好相反,必须放在func里使用

func aoo(){
    guard let name = oName,let age = oAge else {
        print("is nil")
        
        return
    }
    print(name + String(age))
}

//Mark: - if let/ guard let
//使用同名的变量接收值,在后续使用的都是非空值,不需要解包
func ifLetDemo(name: String?, age: Int?){
    if let name = name, let age = age {
        print(name + String(age))
        print("-------")
    }
    
    guard let name = name, let age = age else {
        print("is nil")
        return
    }
    print(name + String(age))
}

ifLetDemo(name: "kalakhang", age: 18)

let arr: Array? = [1,"11"]



 
